package com.atguigu07.encapsulation.exer2;

/**
 * ClassName: Book
 * Package: com.atguigu07.encapsulation.exer2
 * Description:
 * 案例：自定义图书类
 * 设定属性包括：
 * 书名bookName
 * 作者author
 * 价格price
 * 方法包括：
 * 相应属性的get/set方法
 * 图书信息介绍等
 *
 * @Author 姜
 * @Create 2023/11/20 17:03
 * @Version 1.0
 */
public class Book {
    private String bookName;
    private String author;
    private double price;

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getBookName() {
        return bookName;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getAuthor() {
        return author;
    }

    public void setPrice(double price) {
        if (price < 0) {
            System.out.println("价格不能为负数");
            return;
        } else {
            this.price = price;
        }
    }

    public double getPrice() {
        return price;
    }

    // 获取图书信息
    public String ShowBookInfo() {
        return "bookName : " + bookName + ", author : " + author + ", price : " + price;
    }
}
